package me.eleme.anubis.openapi.oauth.request;

import me.eleme.anubis.openapi.config.Config;
import me.eleme.anubis.openapi.config.Constants;
import me.eleme.anubis.openapi.config.oauth.response.Token;
import me.eleme.anubis.openapi.oauth.BaseOauthRequest;

import java.util.Map;

/**
 * @author liuzhiyong
 */
public class ServerTokenRequest extends BaseOauthRequest {
    private final Config context;
    public ServerTokenRequest(Config context) {
        this.context = context;
    }
    private String code;
    private String redirectUri;
    private String merchantId;
    private String timestamp;

    private String signature;

    @Override
    public Class<Token> getResponseClass() {
        return Token.class;
    }

    @Override
    public Map<String, String> getHeaderMap()  {
        setAuthorization(context.getAppId(), context.getSecretKey(), Constants.TOKEN_SIGN);
        return super.headerMap;
    }

    @Override
    public Map<String, String> getBodyMap()  {
        putBodyParam("grant_type", "authorization_code");
        putBodyParam("code", this.code);
        putBodyParam("merchant_id", this.getMerchantId());
        putBodyParam("app_id", context.getAppId());
        putBodyParam("timestamp", this.getTimestamp());
        putBodyParam("signature", this.getSignature());
        return super.bodyMap;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setRedirectUri(String redirectUri) {
        this.redirectUri = redirectUri;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }
}